package org.pmt.first.kms.data.network

import arrow.core.Either
import io.ktor.client.HttpClient
import io.ktor.client.call.body
import io.ktor.client.request.get
import io.ktor.client.request.parameter
import org.pmt.first.kms.data.entity.NewsHotResponse
import org.pmt.first.kms.data.entity.NewsResponse

class OnlineRepository(private val client: HttpClient) {

    suspend fun getWanNews(): String {
        return client.get(NEWS_LIST_URL) {
            parameter("key", NEWS_KEY)
        }.body<String>()
    }

    suspend fun getNewsList(): Either<HttpError, NewsResponse> =
        httpRequest(client) {
            get(NEWS_LIST_URL) {
                parameter("key", NEWS_KEY)
            }
        }

    suspend fun getNewsHot(): Either<HttpError, NewsHotResponse> =
        httpRequest(client) {
            get(NEWS_HOT_URL) {
                parameter("key", NEWS_KEY)
            }
        }
}
